@extends('admin::layouts.master')
@section('content')
    <div class="card" id="app">
        <div class="card-header">文章管理</div>
        <ul role="tablist" class="nav nav-tabs">
            <li class="nav-item"><a href="/shop/article" class="nav-link">文章列表</a></li>
            <li class="nav-item"><a href="#" class="nav-link active">添加文章</a></li>
        </ul>
        <form action="/shop/article" method="post">
            <div class="card-body card-body-contrast">
                @csrf
                <div class="form-group row">
    <label for="title" class="col-12 col-sm-3 col-form-label text-md-right">标题</label>
    <div class="col-12 col-md-9">
        <input id="title" name="title" type="text"
               value="{{ $article['title']??old('title') }}"
               class="form-control form-control-sm form-control{{ $errors->has('title') ? ' is-invalid' : '' }}">
        @if ($errors->has('title'))
            <span class="invalid-feedback" role="alert">
                <strong>{{$errors->first('title')}}</strong>
            </span>
        @endif
    </div>
</div>
<div class="form-group row">
    <label for="author" class="col-12 col-sm-3 col-form-label text-md-right">作者</label>
    <div class="col-12 col-md-9">
        <input id="author" name="author" type="text"
               value="{{ $article['author']??old('author') }}"
               class="form-control form-control-sm form-control{{ $errors->has('author') ? ' is-invalid' : '' }}">
        @if ($errors->has('author'))
            <span class="invalid-feedback" role="alert">
                <strong>{{$errors->first('author')}}</strong>
            </span>
        @endif
    </div>
</div>


    <div class="form-group row">
        <label for="summary" class="col-12 col-sm-3 col-form-label text-md-right">文章简介</label>
        <div class="col-12 col-md-9">
            <input id="summary"  name="summary" type="text"
                   value="{{ $article['summary']??old('summary') }}"
                   class="form-control form-control-sm form-control{{ $errors->has('summary') ? ' is-invalid' : '' }}">
            @if ($errors->has('summary'))
                <span class="invalid-feedback" role="alert">
    <strong>{{$errors->first('summary')}}</strong>
</span>
            @endif
        </div>
    </div>





<div class="form-group row">
    <label for="thumb" class="col-12 col-sm-3 col-form-label text-md-right">所属分类</label>
    <div class="col-12 col-lg-9">


        <select class="form-control" name="category_id">

            @foreach($gory as $v)
                <option value="{{$v['id']}}">{{$v['shopname']}}</option>
            @endforeach

        </select>


    </div>
</div>







<div class="form-group row">
    <label for="content" class="col-12 col-sm-3 col-form-label text-md-right"  style="padding-top:initial;">内容</label>
    <div class="col-12 col-md-9">

        {{--<hd-simditor name="content" url="/upload-simditor">{{ $article['content']??old('content') }}</hd-simditor>--}}
        <textarea name="content" id="container" style="height:300px;width:100%;"></textarea>
        <script>
            require(['hdjs'], function (hdjs) {
                hdjs.ueditor('container', {hash: 2, data: 'hd'}, function (editor) {
                    console.log('编辑器执行后的回调方法1')
                });
            })
        </script>

    </div>
</div>


<div class="form-group row">
    <label for="thumb" class="col-12 col-sm-3 col-form-label text-md-right">缩略图</label>
    <div class="col-12 col-lg-9">
        {{--<hd-image name="thumb" id="thumb" image-url="{!! $article['thumb'] !!}"></hd-image>--}}

            <div class="input-group mb-1">
                <input class="form-control  form-control-sm" name="thumb" readonly="" value="">
                <div class="input-group-append">
                    <button onclick="upImagePc(this)" class="btn btn-secondary" type="button">单图上传</button>
                </div>
            </div>
            <div style="display: inline-block;position: relative;">
                <img src="/img/4041.jpg" class="img-responsive img-thumbnail" width="150">
                <em class="close" style="position: absolute;top: 3px;right: 8px;" title="删除这张图片"
                    onclick="removeImg(this)">×</em>
            </div>

        <script>
            require(['hdjs','bootstrap']);
            //上传图片
            function upImagePc() {
                require(['hdjs'], function (hdjs) {
                    var options = {
                        multiple: false,//是否允许多图上传
                        //data是向后台服务器提交的POST数据
                        data: {name: '后盾人', year: 2099},
                    };
                    hdjs.image(function (images) {
                        //上传成功的图片，数组类型
                        $("[name='thumb']").val(images[0]);
                        $(".img-thumbnail").attr('src', images[0]);
                    }, options)
                });
            }
            //移除图片
            function removeImg(obj) {
                $(obj).prev('img').attr('src', '../dist/static/image/nopic.jpg');
                $(obj).parent().prev().find('input').val('');
            }
        </script>


    </div>
</div>





<div class="form-group row">
    <label for="click" class="col-12 col-sm-3 col-form-label text-md-right">查看次数</label>
    <div class="col-12 col-md-9">
        <input id="click" name="click" type="text"
               value="0"
               class="form-control form-control-sm form-control{{ $errors->has('click') ? ' is-invalid' : '' }}">
        @if ($errors->has('click'))
            <span class="invalid-feedback" role="alert">
                <strong>{ $errors->first('click') }</strong>
            </span>
        @endif
    </div>
</div>
<div class="form-group row">
    <label for="iscommend" class="col-12 col-sm-3 col-form-label text-md-right" style="padding-top:initial;">推荐</label>
    <div class="col-12 col-md-9">
        <div class="form-check form-check-inline">
            <input class="form-check-input" type="radio"
                   {{$article['iscommend']=='1'?'checked':''}}
                   name="iscommend" value="1"
                   id="iscommend-1">
            <label class="form-check-label" for="iscommend-1">是</label>
        </div>
        <div class="form-check form-check-inline">
            <input class="form-check-input" type="radio"
                   checked
                   {{--{{$article['iscommend']=='2'?'checked':''}}--}}
                   name="iscommend" value="2"
                   id="iscommend-2">
            <label class="form-check-label" for="iscommend-2">否</label>
        </div>
    </div>
</div>




                {{--地图接口--}}
                {{--<div class="form-group row">--}}
                    {{--<div id="allmap" style="height: 600px">--}}
                    {{--</div>--}}
                {{--</div>--}}

            </div>

            <div class="card-footer text-muted">
                <button class="btn btn-primary offset-sm-2">保存提交</button>
            </div>
        </form>

    </div>



@endsection

@section('script')

    <script type="text/javascript">
        // 百度地图API功能
        var map = new BMap.Map("allmap");    // 创建Map实例
        map.centerAndZoom(new BMap.Point(116.404, 39.915), 11);  // 初始化地图,设置中心点坐标和地图级别
        //添加地图类型控件
        map.addControl(new BMap.MapTypeControl({
            mapTypes:[
                BMAP_NORMAL_MAP,
                BMAP_HYBRID_MAP
            ]}));
        map.setCurrentCity("北京");          // 设置地图显示的城市 此项是必须设置的
        map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
    </script>


    @endsection


